Skip to content

iio: dac: Add AD5413 support#2786

Open
BruceTsaoADI wants to merge 8 commits into
analogdevicesinc:mirror_ci/jic23/iio/testingfrom
BruceTsaoADI:add-ad5413-driver
Open

iio: dac: Add AD5413 support#2786
BruceTsaoADI wants to merge 8 commits into
analogdevicesinc:mirror_ci/jic23/iio/testingfrom
BruceTsaoADI:add-ad5413-driver

Conversation

@BruceTsaoADI
Copy link
Copy Markdown

Summary

This PR adds initial support for the Analog Devices AD5413, a 14-bit single-channel DAC capable of voltage and current output.

Key changes

  • New driver: ad5413.c under drivers/iio/dac/
  • Devicetree binding: adi,ad5413.yaml under Documentation/devicetree/bindings/iio/dac/
  • Integrated with Kconfig and Makefile

Datasheet:

https://www.analog.com/media/en/technical-documentation/data-sheets/ad5413.pdf

PR Description

  • Please replace this comment with a summary of your changes, and add any context
    necessary to understand them. List any dependencies required for this change.
  • To check the checkboxes below, insert a 'x' between square brackets (without
    any space), or simply check them after publishing the PR.
  • If you changes include a breaking change, please specify dependent PRs in the
    description and try to push all related PRs simultaneously.

PR Type

  • Bug fix (a change that fixes an issue)
  • New feature (a change that adds new functionality)
  • Breaking change (a change that affects other repos or cause CIs to fail)

PR Checklist

  • I have conducted a self-review of my own code changes
  • I have tested the changes on the relevant hardware
  • I have updated the documentation outside this repo accordingly (if there is the case)

Copy link
Copy Markdown
Collaborator

@gastmaier gastmaier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the warnings that caused the ci to exit with an error but were not logged

Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread Documentation/devicetree/bindings/iio/dac/adi,ad5413.yaml Outdated
Comment thread Documentation/devicetree/bindings/iio/dac/adi,ad5413.yaml Outdated
Comment thread Documentation/devicetree/bindings/iio/dac/adi,ad5413.yaml Outdated
Comment thread Documentation/devicetree/bindings/iio/dac/adi,ad5413.yaml Outdated
Comment thread Documentation/devicetree/bindings/iio/dac/adi,ad5413.yaml Outdated
Comment thread drivers/iio/dac/ad5413.c
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c
Comment thread Documentation/devicetree/bindings/iio/dac/adi,ad5413.yaml Outdated
Comment thread Documentation/devicetree/bindings/iio/dac/adi,ad5413.yaml Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
@BruceTsaoADI BruceTsaoADI force-pushed the add-ad5413-driver branch 3 times, most recently from ba5d87d to 1401608 Compare June 29, 2025 05:51
Comment thread Documentation/devicetree/bindings/iio/dac/adi,ad5413.yaml Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread Documentation/devicetree/bindings/iio/dac/adi,ad5413.yaml
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
@gastmaier
Copy link
Copy Markdown
Collaborator

gastmaier commented Jul 4, 2025

Hi, sorry for the pr failure, I updated the checkout strategy to retry by deepening the fetch until the rebase succeeds.
(It is not mega clear to me why it was failing in the first place, the total depth should be 7 (ahead + behind), but rebase only succeeds with around 24 or so.)

please see CI output, checkpatch is failing for example

Comment thread Documentation/devicetree/bindings/iio/dac/adi,ad5413.yaml Outdated
@BruceTsaoADI
Copy link
Copy Markdown
Author

Hi @dlech, @mhennerich, @nunojsa,

All feedback so far has been addressed in the latest commits.
CI still shows some false positives (e.g. checkpatch whitespace), but local checks pass with --strict and no errors.

Could you kindly take a look and let me know if anything else is required for approval?

Thanks!

@BruceTsaoADI BruceTsaoADI force-pushed the add-ad5413-driver branch 9 times, most recently from 15694b1 to 8174327 Compare September 14, 2025 09:41
@gastmaier gastmaier force-pushed the mirror_ci/jic23/iio/testing branch from 4674362 to 78b10cd Compare April 27, 2026 00:12
@nunojsa
Copy link
Copy Markdown
Collaborator

nunojsa commented Apr 27, 2026

@BruceTsaoADI please properly rebase your patches on top of the target branch.

@gastmaier gastmaier force-pushed the mirror_ci/jic23/iio/testing branch 8 times, most recently from 6114e4f to e196cfc Compare May 5, 2026 00:12
maxskiier and others added 6 commits May 5, 2026 13:45
Replace mutex_lock() and mutex_unlock() calls in rm3100-core.c with
the more modern guard(mutex)() family. This will help modernize the
driver and bring it up-to-date with modern available macros/functions.

While replacing mutex_lock() and mutex_unlock(), the critical sections
of rm3100_read_mag() and rm3100_get_samp_freq() have been extended to
include negligible operations for cleaner logic.

Add new helper-wrapper function rm3100_guarded_regmap_bulk_read() to
help keep rm3100_trigger_handler() switch-cases clean while maintaining
mutex locking and avoiding re-entrancy risks from potential callbacks.

While at it, remove redundant gotos where applicable, and use direct
returns instead. In addition, remove regmap variable in
rm3100_trigger_handler() as its references have been replaced with
variable data.

Suggested-by: Jonathan Cameron <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
Signed-off-by: Maxwell Doose <[email protected]>
Signed-off-by: Jonathan Cameron <[email protected]>
Rewrite MCP3422_CHANNEL_MASK, MCP3422_SRATE_MASK, MCP3422_PGA_MASK
and MCP3422_CONT_SAMPLING using GENMASK() and BIT() macros from
bits.h.

The other macros MCP3422_SRATE_{240, 60, 15, 3} were not changed
because they are also used as array indices.

Signed-off-by: Marcelo Machado Lage <[email protected]>
Co-developed-by: Vinicius Lira <[email protected]>
Signed-off-by: Vinicius Lira <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
Signed-off-by: Jonathan Cameron <[email protected]>
Replace manual bit manipulations with FIELD_GET(), FIELD_PREP() and
FIELD_MODIFY() calls. The resulting code is more readable and
maintainable, and 6 macros previously defined in the header are not
needed anymore.

Signed-off-by: Marcelo Machado Lage <[email protected]>
Co-developed-by: Vinicius Lira <[email protected]>
Signed-off-by: Vinicius Lira <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
Signed-off-by: Jonathan Cameron <[email protected]>
Use guard(mutex)() for handling mutex lock instead of
manually locking and unlocking the mutex. This prevents forgotten
locks due to early exits and removes the need of gotos.

Signed-off-by: Pedro Barletta Gennari <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
Signed-off-by: Jonathan Cameron <[email protected]>
Handle errors as early as possible by replacing 'if (!ret)' with the
more common form 'if (ret)'. This makes the code easier to read.

Signed-off-by: Pedro Barletta Gennari <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
Signed-off-by: Jonathan Cameron <[email protected]>
patch ci

Signed-off-by: CSE CI <[email protected]>
@gastmaier gastmaier force-pushed the mirror_ci/jic23/iio/testing branch from e196cfc to fdad854 Compare May 6, 2026 00:11
Document the devicetree bindings for the Analog Devices AD5413, a
single-channel precision DAC controlled via SPI. The device supports
voltage or current output modes and programmable slew-rate control.

Signed-off-by: Bruce Tsao <[email protected]>
@BruceTsaoADI
Copy link
Copy Markdown
Author

BruceTsaoADI commented May 6, 2026

@BruceTsaoADI please properly rebase your patches on top of the target branch.

Thanks @nunojsa .

I fetched the latest mirror_ci/jic23/iio/testing target branch and rebased the two AD5413 patches on top of fdad854.

The PR branch has been force-pushed again. CI is now passing and there are no conflicts with the base branch.

@gastmaier gastmaier force-pushed the mirror_ci/jic23/iio/testing branch 5 times, most recently from ae283b1 to dcb3553 Compare May 11, 2026 00:14
Copy link
Copy Markdown
Collaborator

@nunojsa nunojsa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it goes my review

Comment thread drivers/iio/dac/ad5413.c
#include <linux/property.h>
#include <linux/spi/spi.h>
#include <linux/units.h>
#include <linux/util_macros.h>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include paths should be in alphabetical order

Comment thread drivers/iio/dac/ad5413.c

MODULE_AUTHOR("Bruce Tsao <[email protected]>");
MODULE_DESCRIPTION("Analog Devices AD5413 DAC");
MODULE_LICENSE("GPL v2");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like you have some warnings here

Comment thread drivers/iio/dac/ad5413.c
{
struct ad5413_state *st;
struct iio_dev *indio_dev;
int ret, i;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment thread drivers/iio/dac/ad5413.c
return ad5413_spi_write_mask(st,
AD5413_REG_DAC_CONFIG,
AD5413_REG_DAC_CONFIG_OUT_EN_MSK,
FIELD_PREP(AD5413_REG_DAC_CONFIG_OUT_EN_MSK, 1));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still issues with formatting

Comment thread drivers/iio/dac/ad5413.c

*val = ret;
return IIO_VAL_INT;
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment thread drivers/iio/dac/ad5413.c
if (ret < 0) {
return dev_err_probe(&st->spi->dev, ret,
"Failed to initiate a calibration memory refresh\n");
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for brackets

Comment thread drivers/iio/dac/ad5413.c
/*
* Poll until the bit clears. ad5413_spi_reg_read() returns a negative
* errno on failure, so stop polling on error and propagate it.
*/
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say you don't need to comment what the API does

Comment thread drivers/iio/dac/ad5413.c
u32 cmd;

cmd = (u32)AD5413_WR_FLAG_MSK(AD5413_REG_TWO_STAGE_READBACK_SELECT) << 24;
cmd |= (u32)addr << 8;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as before?

Comment thread drivers/iio/dac/ad5413.c
if (ret < 0)
return ret;

return (be32_to_cpu(st->d32[2]) >> 8) & 0xFFFF;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh just noticed this now. Don't mix error codes (returns) with proper read values. It just makes it weird. Just pass in a proper u16 * pointer as a argument and set it:

*val = be32_to_cpu(st->d32[2]) >> 8

Then no need for the mask as we already have an implicit cast to u16

@nunojsa
Copy link
Copy Markdown
Collaborator

nunojsa commented May 11, 2026

@BruceTsaoADI if you rebase again on top of testing so that only your two patches exist, we can trigger a final LLM review on your series before going upstream.

@gastmaier gastmaier force-pushed the mirror_ci/jic23/iio/testing branch 2 times, most recently from 1719553 to 55ab0e3 Compare May 13, 2026 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants